//
//  RefundObject.m
//  YangDongXi
//
//  Created by 杨鑫 on 15/10/16.
//  Copyright (c) 2015年 yangdongxi. All rights reserved.
//

#import "RefundObject.h"
//#import "MKNetworking+BusinessExtension.h"
#import "NSDictionary+MKExtension.h"
//#import "MBProgressHUD+MKExtension.h"
//#import "AFHTTPRequestOperationManager.h"
//#import "BlackView.h"
//#import "BlackWaitView.h"
//#import "NSArray+MKExtension.h"
#import "AppDelegate.h"
//#import "UpYun.h"

@interface RefundObject ()

@property (nonatomic,assign)NSInteger stap;
@property (nonatomic,strong)NSMutableArray *imageUrl;

//@property (nonatomic,strong)BlackView *promptView;
//@property (nonatomic,strong)BlackWaitView *balckWaitView;
@property (nonatomic,strong)UITapGestureRecognizer *recognizer;



@end
@implementation RefundObject
- (UIView *)pickView{
    if (!_pickView) {
        self.pickView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
        _pickView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        self.recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAction:)];
        self.recognizer.numberOfTapsRequired = 1;
        [self.pickView addGestureRecognizer:self.recognizer];
       
    }
    return _pickView;
}

//- (void)handleTapAction:(UITapGestureRecognizer *)sender{
//    [self.pickView removeFromSuperview];
//    [[AFHTTPRequestOperationManager manager].operationQueue cancelAllOperations];
//    self.stap = 0;
//}
//- (void)uploadData{
//    self.stap = 0;
//    self.imageUrl = [NSMutableArray array];
//    UIWindow *win = [[UIApplication sharedApplication].delegate window];
////    self.promptView = [[BlackView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
////    self.promptView.center = win.center;
////    [self.pickView addSubview:self.promptView];
//   
//    if (self.imageData.count>0) {
//        self.balckWaitView = [[BlackWaitView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
//        self.balckWaitView.center = win.center;
//        [self.balckWaitView.plck startAnimating];
//        self.balckWaitView.blackLabelView.text = [NSString stringWithFormat:@"正在上传图片%ld/%ld",self.stap,self.imageData.count];
//        [self.pickView addSubview:self.balckWaitView];
//        [win addSubview:self.pickView];
//        for (NSData *da in self.imageData) {
//            [self uploadImageData:da];
//        }
//    }else{
//        [self notImageUploadData];
//    }
//}

//- (void)uploadImageData:(NSData *)data{
//    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//    // 设置时间格式
//    formatter.dateFormat = @"yyyyMMddHHmmss";
//    NSString *str = [formatter stringFromDate:[NSDate date]];
//    NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
//    [[AFHTTPRequestOperationManager manager] POST:@"http://b.taojae.com/service.php" parameters:@{@"media_auth_key":@"6r4XkF6EcE"} constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//        [formData appendPartWithFileData:data name:@"images" fileName:fileName mimeType:@"image/png"];
//    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        if ([[NSString stringWithFormat:@"%@",responseObject[@"code"]] isEqualToString: @"10000"]){
//            [self.imageUrl addObject:responseObject[@"data"][@"thumb"]];
//            self.stap ++;
//            self.balckWaitView.blackLabelView.text = [NSString stringWithFormat:@"正在上传图片%ld/%ld",self.stap,self.imageData.count];
//            NSLog(@"%@",responseObject);
//            if (self.stap == self.imageData.count) {
//                [self.pickView removeFromSuperview];
//                [self notImageUploadData];
//            }
//        }
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        
//    }];
//}


//- (void)uploadImageData:(NSData *)data{
//    NSString * dateString = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]];
//    NSString *fileName = [NSString stringWithFormat:@"%@.png",dateString];
//    
//    [UPYUNConfig sharedInstance].DEFAULT_BUCKET = @"pict2";
//    [UPYUNConfig sharedInstance].DEFAULT_PASSCODE = @"oO8pSqnH3nmd1uAq61gvR7jbS54=";
//    __block UpYun *uy = [[UpYun alloc] init];
//    uy.successBlocker = ^(NSURLResponse *response, id responseData) {
//
//        NSLog(@"response body %@", responseData);
//        self.stap++;
//        NSString *url = [NSString stringWithFormat:@"%@%@", @"http://img1.pic.ybaby.com/", fileName];
//        [self.imageUrl addObject:url];
//        NSLog(@"~~~~~~~~%@",url);
//        if (self.stap == self.imageData.count) {
//            [self.pickView removeFromSuperview];
//            [self notImageUploadData];
//        }
//        
//    };
//    uy.failBlocker = ^(NSError * error) {
//        NSString *message = [error.userInfo objectForKey:@"message"];
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"message" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
//        [alert show];
//        NSLog(@"error %@", message);
//    };
//    uy.progressBlocker = ^(CGFloat percent, int64_t requestDidSendBytes) {
//        NSLog(@"percent %.4f", percent);
//    };
//    //    [uy.params setObject:@"" forKey:@""];
//    //[uy uploadLivePhoto:_livePhotoAsset saveKey:@"testLive2"];
//    [uy uploadFile:data saveKey:fileName];
//    
//    
//}


//- (void)notImageUploadData{
////    NSString *price = [NSString stringWithFormat:@"%f",self.refund_amount.floatValue *100];
////    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
////    [dict setObject:self.refund_reason_id forKey:@"backreason"];
////    [dict setObject:@(self.refund_amount.floatValue *100) forKey:@"backprice"];
////    [dict setObject:self.refund_desc forKey:@"back_remark"];
////    [dict setObject:self.orderUid forKey:@"order_uid"];
//    NSMutableArray *backOrderItemList = [NSMutableArray array];
//    for (MKOrderItemObject *item in self.orderItemList) {
//        NSMutableDictionary *dicItem = [NSMutableDictionary dictionary];
//        [dicItem setObject:item.itemUid forKey:@"item_uid"];
//        [dicItem setObject:@(item.number) forKey:@"number"];
//        [dicItem setObject:item.orderItemUid forKey:@"order_item_uid"];
//        [backOrderItemList addObject:dicItem];
//    }
////    [dict setObject:backOrderItemList forKey:@"backOrderItemList"];
////    [dict setObject:@(3) forKey:@"apply_credentials"];
////    [dict setObject:@(0) forKey:@"back_way"];
////    [dict setObject:@(self.isBack) forKey:@"is_back"];
//    NSMutableArray *muta = [NSMutableArray array];
//    if (self.imageUrl.count>0) {
//        for (NSString *str in self.imageUrl) {
//            [muta addObject:str];
//        }
////        [dict setObject:muta forKey:@"images"];
//    }
//    if ([self.refund_desc isEqualToString:@""]) {
//        [MBProgressHUD showMessage:@"请填写备注" wait:NO];
//        return;
//    }
//    [MKNetworking MKSeniorPostApi:@"trade/refund/apply" paramters:@{@"backOrderItemList":[backOrderItemList jsonString],@"order_uid":self.orderUid,@"backreason":self.refund_reason_id,@"backprice":@(self.refund_amount.floatValue *100),@"back_remark":self.refund_desc,@"apply_credentials":@(3),@"back_way":@(0),@"is_back":@(self.isBack),@"images":[muta jsonString]} completion:^(MKHttpResponse *response) {
//        NSLog(@"%@",response.errorMsg);
//        if (response.errorMsg) {
//            [MBProgressHUD showMessage:response.errorMsg wait:NO];
//            return ;
//        }
//            self.promptView = [[BlackView alloc]initWithFrame:CGRectMake(0, 0, 200, 300)];
//        UIWindow *win = [[UIApplication sharedApplication].delegate window];
//            self.promptView.center = win.center;
//            [self.pickView addSubview:self.promptView];
//            [win addSubview:self.pickView];
//                self.tmpe();
//    }];
//}
@end
